package com.KOL.present.game;

import com.KOL.model.character.PlayerCharacter;
import javax.swing.JFrame;
import java.awt.Container;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import javax.swing.JPanel;

public class GameWindow extends JFrame implements WindowListener{
    public final static String WINDOW_TITLE = "Dragon's Gate";
    public final static int WINDOW_HEIGHT = 720;
    public final static int WINDOW_WIDTH = 1280;
    public final static int WINDOW_X = 100;
    public final static int WINDOW_Y = 100;
    
    private Game game;
    private CreationWindow creationWindow;

    public GameWindow(long period) {
        super("Kingdom Of Llenoquelle");
        setupWindow(period);
    }

    public final void setupWindow(long period) {

        addWindowListener( this );
        pack();
        setResizable(false);
        setVisible(true);
    }

    public void addPanel(JPanel panel) {
        if(panel instanceof Game)
            game = (Game)(panel);
        else if(panel instanceof CreationWindow)
            creationWindow = (CreationWindow)(panel);

        Container c = getContentPane();
        c.add(panel, "Center");
        pack();
        setVisible(true);
    }

    public void windowActivated(WindowEvent e) {
        if(game != null)
            game.resumeGame();
    }

    public void windowDeactivated(WindowEvent e) { 
        if(game != null)
            game.pauseGame();
    }

    public void windowDeiconified(WindowEvent e) {  
        if(game != null)
            game.resumeGame();
    }

    public void windowIconified(WindowEvent e) {  
        if(game != null)
            game.pauseGame();
    }

    public void windowClosing(WindowEvent e) {  
        if(game != null)
            game.stopGame();
    }

    public void windowClosed(WindowEvent e) {}
    public void windowOpened(WindowEvent e) {}
}
